<?php

class Application_Model_DbTable_Customers extends Zend_Db_Table_Abstract
{

    protected $_name = 'customers';

    public function getCustomer($cust_no)
    {
    	$cust_no = (int)$cust_no;
    	$row = $this->fetchRow('cust_no = ' . $cust_no);
    	if (!$row) {
    		throw new Exception("Could not find row $cust_no");
    	}
    	return $row->toArray();
    }

    public function addCustomer($cust_title, $cust_first_name, $cust_last_name, $cust_address, $cust_suburb, $cust_state, $cust_post_code, $cust_home_phone, $cust_work_phone, $cust_mobile_phone, $cust_pay_method)
    {
    	$data = array(
    		'cust_title' => $cust_title,
    		'cust_first_name' => $cust_first_name,
    		'cust_last_name' => $cust_last_name,
    		'cust_address' => $cust_address,
    		'cust_suburb' => $cust_suburb,
    		'cust_state' => $cust_state,
    		'cust_post_code' => $cust_post_code,
    		'cust_home_phone' => $cust_home_phone,
    		'cust_work_phone' => $cust_work_phone,
    		'cust_mobile_phone' => $cust_mobile_phone,
    		'cust_pay_method' => $cust_pay_method,
    	);
    	$this->insert($data);
    }
    
    public function updateCustomer($cust_no, $cust_title, $cust_first_name, $cust_last_name, $cust_address, $cust_suburb, $cust_state, $cust_post_code, $cust_home_phone, $cust_work_phone, $cust_mobile_phone, $cust_pay_method)
    {
    	
    	if ($cust_title != false) {
    		//$data = array_merge(array('cust_title' => $cust_title));
    		$data['cust_title'] = $cust_title;
    	}
    	if ($cust_first_name != false) {
    		//$data = array_merge($data, array('cust_first_name' => $cust_first_name));
    		$data['cust_first_name'] = $cust_first_name;
    	}
    	if ($cust_last_name != false) {
    		//$data = array_merge($data, array('cust_last_name' => $cust_last_name));
    		$data['cust_last_name'] = $cust_last_name;
    	}
    	if ($cust_address != false) {
    		//$data = array_merge($data, array('cust_address' => $cust_address));
    		$data['cust_address'] = $cust_address;
    	}
    	if ($cust_suburb != false) {
    		//$data = array_merge($data, array('cust_suburb' => $cust_suburb));
    		$data['cust_suburb'] = $cust_suburb;
    	}
    	if ($cust_state != false) {
    		//$data = array_merge($data, array('cust_state' => $cust_state));
    		$data['cust_state'] = $cust_state;
    	}
    	if ($cust_post_code != false) {
    		//$data = array_merge($data, array('cust_post_code' => $cust_post_code));
    		$data['cust_post_code'] = $cust_post_code;
    	}
    	if ($cust_home_phone != false) {
    		//$data = array_merge($data, array('cust_home_phone' => $cust_home_phone));
    		$data['cust_home_phone'] = $cust_home_phone;
    	}
    	if ($cust_work_phone != false) {
    		//$data = array_merge($data, array('cust_work_phone' => $cust_work_phone));
    		$data['cust_work_phone'] = $cust_work_phone;
    	}
    	if ($cust_mobile_phone != false) {
    		//if ($cust_mobile_phone = ''){
    			//$cust_mobile_phone = '54321';
    		//}
    		//$cust_mobile_phone = '54321';
    		//$data = array_merge($data, array('cust_mobile_phone' => $cust_mobile_phone));
    		$data['cust_mobile_phone'] = $cust_mobile_phone;
    	}
    	if ($cust_pay_method != false) {
    		$data['cust_pay_method'] = $cust_pay_method;
    	}
    	
    	if (isset($data)) {
    		$this->update($data, 'cust_no = ' . (int)$cust_no);
    	}
    }
    
    public function searchCustomer($cust_no, $cust_first_name, $cust_last_name, $cust_suburb, $cust_post_code, $cust_phone)
    {
    	$data = array(
    		'cust_no' => $cust_no,
    		'cust_first_name' => $cust_first_name,
    		'cust_last_name' => $cust_last_name,
    		'cust_suburb' => $cust_suburb,
    		'cust_post_code' => $cust_post_code,
    		'cust_phone' => $cust_phone,
    	);
    }
    public function givecatCustomer($cust_no, $cust_catalogue)
    {
    	$data = array(
    		'cust_catalogue' => $cust_catalogue
    		
    	);
    	$this->update($data, 'cust_no = '. (int)$cust_no);
    	
    }
    
}

